package com.baayso.bms2.role;

import java.util.List;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.ManyToMany;
import javax.persistence.Table;

import org.apache.commons.lang3.builder.ToStringBuilder;

import com.baayso.bms2.core.entity.IdEntity;
import com.baayso.bms2.permission.Permission;
import com.baayso.bms2.user.User;

/**
 * 角色表。
 * 
 * @author ChenFangjie(2015年9月20日 上午11:15:13)
 * 
 * @since 1.0.0
 * 
 * @version 1.0.0
 * 
 */
@Entity
@Table(name = "t_role")
public class Role extends IdEntity {

    private static final long serialVersionUID = -212182773095069019L;

    @Column(length = 60, nullable = false)
    private String name;
    private String descriptions;

    @ManyToMany(targetEntity = User.class, mappedBy = "roles")
    private List<User> users;

    @ManyToMany(targetEntity = Permission.class, mappedBy = "roles")
    private List<Permission> permission; // 所拥有的权限

    @Override
    public String toString() {
        return ToStringBuilder.reflectionToString(this);
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getDescriptions() {
        return descriptions;
    }

    public void setDescriptions(String descriptions) {
        this.descriptions = descriptions;
    }

    public List<User> getUsers() {
        return users;
    }

    public void setUsers(List<User> users) {
        this.users = users;
    }

    public List<Permission> getPermission() {
        return permission;
    }

    public void setPermission(List<Permission> permission) {
        this.permission = permission;
    }

}
